'use strict'
app.service('fullReductionEditService', ['$q', 'utilService', function ($q, utilService) {
    var _this_ = this;
    _this_.editFullReduction = function ($scope) {
        var deferred = $q.defer();
        var dataForm = new Object();
        dataForm.fullReductionVO = JSON.stringify($scope.fullReductionVO);
        dataForm.fullReductionConditionVO = JSON.stringify($scope.fullReductionConditionJson);
        dataForm.fullReductionGoodsVO = JSON.stringify($scope.fullReductionGoodsVO);
        utilService.api({
            url: $scope.app.domain + "full/reduction",
            data: dataForm,
            method:'PUT'
        }).then(function (rlt) {
            deferred.resolve(rlt);
        })
        return deferred.promise;
    }
    _this_.queryForCoupon = function ($scope) {
        var deferred = $q.defer();
        utilService.get({
            url: $scope.app.domain + "coupons/all"
        }).then(
            function (res) {
                deferred.resolve(res.data);
            }, function (e) {
                deferred.reject("连接服务器出错");
            }
        );
        return deferred.promise;
    }
    _this_.queryForGoods = function ($scope) {
        var deferred = $q.defer();
        utilService.get({
            url: $scope.app.domain + "goods/all",
            params:{
                startTime:$scope.fullReductionVO.startTime,
                endTime:$scope.fullReductionVO.endTime,
                fullReductionId:$scope.fullReductionVO.id
            }
        }).then(
            function (res) {
                deferred.resolve(res.data);
            }, function (e) {
                deferred.reject("连接服务器出错");
            }
        );
        return deferred.promise;
    }
    _this_.queryById = function ($scope) {
        var deferred = $q.defer();
        utilService.get({
            url: $scope.app.domain + "full/reduction/id",
            params: $scope.fullReductionVO
        }).then(function (rlt) {
            deferred.resolve(rlt.data);
        });
        return deferred.promise;
    }
}]);